package com.gobang.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import com.gobang.control.Controller;

public class GobangFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private ChessboardPanel chessboardPanel;
	private ControlPanel controlPanel;
	private Controller controller;
	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				new GobangFrame();
			}
		});
	}

	public GobangFrame() {
		initialize();
	}

	private void initialize() {
		controller = new Controller();
		chessboardPanel = new ChessboardPanel(controller);
		controlPanel = new ControlPanel(controller);
		
		this.setSize(controller.getFrameWidth(), controller.getFrameHeight());
		this.setContentPane(getJContentPane());
		this.setTitle("简易五子棋");
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setResizable(false);
		setLocationRelativeTo(null);
		this.setVisible(true);
	}

	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setBackground(Color.WHITE);
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(chessboardPanel, BorderLayout.CENTER);
			
			controlPanel.setPreferredSize(new Dimension(200, 100));
			jContentPane.add(controlPanel, BorderLayout.EAST);
		}
		return jContentPane;
	}

}
